package com.hbt.feature_consumer.controller;

import com.hbt.api.entity.CommonResult;
import com.hbt.api.entity.User;
import com.hbt.api.entity.Word;
import com.hbt.feature_consumer.service.FeatureFeign;
import com.hbt.feature_consumer.service.FeatureUserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("feature_consumer")
public class FeatureConsumerController {
    @Autowired
    FeatureUserFeign featureUserFeign;
    @Autowired
    FeatureFeign featureFeign;



    @PostMapping("del_feature")
    public CommonResult delFeature(String descript, int wordid){
//        return featureFeign.addFeature(descript, wordid);
        return featureFeign.delFeature(descript, wordid);
    }

    @PostMapping("add_feature")
    public CommonResult addFeature(String descript, int wordid){
        return featureFeign.addFeature(descript, wordid);
    }

    @RequestMapping("changeSysFeatures")
    public CommonResult changeSysFeatures(@RequestParam("features") List<String> features, @RequestParam("token") String token){
        System.out.println(" changeSysFeatures method features legnth:"+features.size());
        System.out.println("changeSysFeatures method token:"+token);
        CommonResult<User> commonResult = featureUserFeign.getUserByToken(token);
        User user = (User)commonResult.getT();
        featureFeign.changeSysFeatures(features,user.getId());
        CommonResult<String> commonResult_1 = new CommonResult<String>();
        commonResult_1.setCode(200);
        commonResult_1.setMsg("改变系统特征成功");
        commonResult_1.setT("改变系统特征成功");

        return commonResult_1;
    }

    @RequestMapping("getSysFeatures")
    public CommonResult<List<String>> getSysFeatures(String token){
        System.out.println("enter getSysFeatures");
        CommonResult<User> commonResult = featureUserFeign.getUserByToken(token);
        User user = commonResult.getT();
        CommonResult<List<String>> commonResult_1 = new CommonResult<List<String>>();
        commonResult_1.setT(featureFeign.getSysFeatures(user.getId()));
        commonResult_1.setMsg("获取系统特征成功");
        commonResult_1.setCode(200);
        return commonResult_1;
    }

}
